package top.lshaci.learning.activiti.day2;

import cn.hutool.core.lang.Dict;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

import static top.lshaci.learning.activiti.util.ProcessEngineSingleton.singleton;

/**
 * DynamicAssignTaskTest
 * <p>自动任务分配测试</p>
 * <pre>
 *     表达式方式：${流程变量key}
 * </pre>
 *
 * @author lshaci
 * @since 1.0.0
 */
public class DynamicAssignTaskTest {

    @Test
    public void test() {
        // 1.部署流程
        Deployment deployment = singleton.deploy("DynamicAssignTask");
        System.err.println(deployment);
        // 2.启动流程
        Dict variables = Dict.create().set("leaveUser", "小张");
        ProcessInstance processInstance = singleton.runtimeService()
                .startProcessInstanceByKey("DynamicAssignTask", variables);
        String processInstanceId = processInstance.getId();
        System.err.println("processInstanceId: " + processInstanceId);
        // 3.查询任务
        Task t1 = singleton.personalTask("小张").get(0);
        System.err.println(t1);

        // 4.完成任务
        singleton.taskService().complete(t1.getId());
    }
}
